import allure
from playwright.sync_api import Page


"""
登录页面
"""
class LoginPage:

    def __init__(self, page: Page):
        # 页面对象
        self.page = page

        # 页面地址
        self.url = "/xxl-job-admin/toLogin"

        # 输入框和登录按钮元素
        self.locator_username = page.get_by_placeholder("请输入登录账号")
        self.locator_password = page.get_by_placeholder("请输入登录密码")
        self.locator_login_btn = page.get_by_role("button", name="登录")

        # 主页导航栏元素
        self.locator_index_nav = page.locator("xpath=//header")

    def navigate(self):
        with allure.step(f"导航到登录页:{self.url}"):
            self.page.goto(self.url)

    def fill_username(self, username):
        with allure.step(f"输入账号:{username}"):
            self.locator_username.fill(username)

    def fill_password(self, password):
        with allure.step(f"输入密码:{password}"):
            self.locator_password.fill(password)

    def click_login_btn(self):
        with allure.step("点击登录"):
            self.locator_login_btn.click()